<?php
namespace plugin\banmichaoqiangbizhi\admin;
use app\admin\common\Baseadmin;
use think\facade\Db; 
use plugin\banmichaoqiangbizhi\common\Common;
use plugin\banmichaoqiangbizhi\validate\NoticeValidate as validates ;
use plugin\banmichaoqiangbizhi\model\PluginbanmichaoqiangbizhiSettingsNotice as models ; 


class Settingsnotice extends Baseadmin
{
    
       protected   $plugin ='banmichaoqiangbizhi';     //插件别名
       protected   $field  ='message_config';  // zenkuai_home_plugin_list_config 表的字段
       protected   $files   ='set_message';     //插件里的php配置文件
 
 
 
    /**
     * 查询json
     * @param index
     * @param    json类型的字段 $output_json
     */
      public function index() {

          $data = (new Common())->get_php_other($this->field , $this->files  );
          ajaxmsg('ok', 200,$data);     
      }

    /**
     * 查询json
     * @param index
     * @param    json类型的字段 $output_json
     */
      public function views() {
          
          

          
          
          $request= (new validates())->IsCheck();
          if (!isset($request['id'])) {
               ajaxmsg('缺失参数', 0);  
          } 
          $id=$request['id'];
          
          $map['id'] = $id;
          
          $ret = (new Common())->get_php_other($this->field , $this->files ,$map );
          
           
          
          $data['find'] = isset($ret['list'][0])?$ret['list'][0]:[];
         
          ajaxmsg('ok', 200,$data);     
      }
    
    
 
    /**
     * 保存
     * @param index
     * @param    json类型的字段 $output_json
     */
      public function save() {
          
      
            $request= (new validates())->IsCheck();
            $find = json_decode($request['find'],true);
            
            
 
            $config=   get_set_config($this->plugin,$this->field,$this->files);
            $list  =   !empty($config['sql_config'])?$config['sql_config']:$config['php_config']['list']; 
            foreach ($list as $key => $value) {
                  if ($find['id']==$value['id']) {
                      $list[$key] = $find;
                      break;
                  }   
            }
            
            
       
         
            
           $list =json_encode($list);
           Db::name('home_plugin_list_config')->where('catalogue', $this->plugin)->update(['message_config' => $list ]);
         
           ajaxmsg('保存成功', 200);     
      }
      
 
  
    
}